package cpasl;

import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;

import javax.swing.JFrame;

public class CpaslFrame extends JFrame {
	
	public CpaslFrame(int participantNumber, File videoDirectory, 
			File imagesDirectory, File outputDirectory, int fileCount) {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		final CpaslPanel panel;
		Toolkit toolkit = Toolkit.getDefaultToolkit();  
		int xSize = ((int) toolkit.getScreenSize().getWidth());  
		int ySize = ((int) toolkit.getScreenSize().getHeight()); 
		panel = new CpaslPanel(participantNumber, xSize, ySize, this,
				videoDirectory, imagesDirectory, outputDirectory, fileCount);
		setUndecorated(true);
		setSize(xSize, ySize);
		setContentPane(panel);
		addWindowListener(new WindowListener() {

			@Override
			public void windowOpened(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void windowClosed(WindowEvent e) {
				panel.closeFile();
			}

			@Override
			public void windowIconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void windowDeiconified(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void windowActivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void windowDeactivated(WindowEvent e) {
				// TODO Auto-generated method stub
				
			}
			
		});
		KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
		keyboardFocusManager.addKeyEventDispatcher(new KeyEventDispatcher() {

			@Override
			public boolean dispatchKeyEvent(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
					System.exit(0);
				}
				return false;
			}
			
		});
	}

}
